package cn.webrx;

import java.util.Calendar;
import java.util.Date;

public class Calendar2 {
    public static void main(String[] args) {
        Calendar c = Calendar.getInstance();
        System.out.println(c.get(1)); //传入一个1 返回一个年份  2022
        System.out.println(c.get(Calendar.YEAR)); //传入一个1 返回一个年份  2022
        System.out.println(c.get(2) + 1);//返回月 7
        System.out.println(c.get(Calendar.DAY_OF_MONTH)); //11 几号
        System.out.println(c.get(5)); //11 几号

        System.out.println("----------------------");
        int year = c.get(Calendar.YEAR);
        int mm = c.get(Calendar.MONTH) + 1;
        int dd = c.get(Calendar.DAY_OF_MONTH);
        //int hh = c.get(Calendar.HOUR); //返回12小时制
        int hh = c.get(Calendar.HOUR_OF_DAY);
        int mi = c.get(Calendar.MINUTE);
        int ss = c.get(Calendar.SECOND);

        System.out.println(year + "年" + mm + "月" + dd + "日 " + hh + ":" + mi + ":" + ss);
        System.out.printf("%d年%02d月%02d日 %02d:%02d:%02d %tA",year,mm,dd,hh,mi,ss,c);

        //格式化输出当前星期几
        System.out.printf("%tA%n",new Date());


        //请计算2001 6 18哪一天是星期？
        Calendar c2 = Calendar.getInstance();
        c2.set(Calendar.YEAR,2001);
        c2.set(Calendar.MONTH,6-1);
        c2.set(Calendar.DAY_OF_MONTH,18);

        System.out.printf("%tF 这一日期是：%tA%n",c2,c2);

    }
}
